package com.attendance.www.hr.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.attendance.www.hr.beans.SalaryRuleBean;
import com.attendance.www.hr.dao.mapper.SalaryRuleExtMapper;
import com.attendance.www.hr.dao.mapper.SalaryRuleMapper;
import com.attendance.www.hr.entitys.SalaryRule;
import com.attendance.www.hr.entitys.SalaryRuleExample;
import com.attendance.www.hr.exception.ResultFaultException;
import com.attendance.www.hr.service.ISalaryRuleService;

@Service
public class SalaryRuleServiceImpl  implements ISalaryRuleService{

	@Resource
	private SalaryRuleMapper salaryRuleDao;
	@Resource
	private SalaryRuleExtMapper salaryRuleExtDao;
	
	
	/**
	 * 查询
	 * @param SalaryRuleBean
	 * @return
	 */
	@Override
	public List<SalaryRuleBean> getSalaryRuleList() {
		List<SalaryRuleBean> salaryRuleList = salaryRuleExtDao.getSalaryRuleList();
		return salaryRuleList;
	}
	
	
	
	/**
	 * 保存验证（只能设置一条规则）
	 * @param salaryRuleBean
	 * @return
	 */

	@Override
	public boolean saveSalaryRule(SalaryRuleBean salaryRuleBean) {
		List<SalaryRule>  srList = salaryRuleDao.selectByExample(new SalaryRuleExample());
		
		if(srList.size()==0){
			SalaryRule salaryRule = new SalaryRule();
			salaryRule.setOneEmployeeNo(salaryRuleBean.getOneEmployeeNo());
			salaryRule.setTwoEmployeeNo(salaryRuleBean.getTwoEmployeeNo());
			salaryRule.setThreeEmployeeNo(salaryRuleBean.getThreeEmployeeNo());;
			salaryRule.setFourEmployeeNo(salaryRuleBean.getFourEmployeeNo());
			salaryRule.setFiveEmployeeNo(salaryRuleBean.getFiveEmployeeNo());
			salaryRule.setCreateTime(salaryRuleBean.getCreateTime());
			int record = salaryRuleDao.insertSelective(salaryRule);
				if(record>0){
					return true;
				}else{
					return false;
				}
		}
		throw new ResultFaultException("18_00001");
}
	/**
	 * 修改
	 * @param SalaryRuleBean
	 */
	@Override
	public boolean updateSalaryRule(SalaryRuleBean salaryRuleBean) {
		SalaryRule salaryRule = salaryRuleDao.selectByPrimaryKey(salaryRuleBean.getSalaryRuleId());
		salaryRule.setSalaryRuleId(salaryRuleBean.getSalaryRuleId());
		salaryRule.setOneEmployeeNo(salaryRuleBean.getOneEmployeeNo());
		salaryRule.setTwoEmployeeNo(salaryRuleBean.getTwoEmployeeNo());
		salaryRule.setThreeEmployeeNo(salaryRuleBean.getThreeEmployeeNo());
		salaryRule.setFourEmployeeNo(salaryRuleBean.getFourEmployeeNo());
		salaryRule.setFiveEmployeeNo(salaryRuleBean.getFiveEmployeeNo());
		salaryRule.setUpdateTime(salaryRuleBean.getUpdateTime());
		int record = salaryRuleDao.updateByPrimaryKey(salaryRule);
		if(record>0){
			return true;
		}else{
			return false;
	    }
	}
	
	/**
	 * 删除
	 * @param  salaryRuleId
	 */
	@Override
	public boolean deleteSalaryRule(Integer salaryRuleId) {
		int record = salaryRuleDao.deleteByPrimaryKey(salaryRuleId);
		if(record>0){
			return true;
		}else{
			return false;
		}
	}
}
